package org.belkodevelop.realty.dao;

import org.belkodevelop.realty.domen.Realty;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class RealtyDAOImpl implements RealtyDAO {

    @Autowired
    private SessionFactory sessionFactory;
    
    @Override
    public void addRealty(Realty realty) {
        sessionFactory.getCurrentSession().save(realty);
    }

    @Override
    public void removeRealty(long id) {
        Query query = sessionFactory.getCurrentSession().
                createQuery("delete from Realty where id = :id");
        query.setParameter("id", id);
        query.executeUpdate();
    }

    @Override
    public Realty getRealtyById(long id) {
        return (Realty)sessionFactory.getCurrentSession().get(Realty.class, new Long(id));
    }

}
